package com.liip.platform.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.liip.platform.common.ReturnT;
import com.liip.platform.entity.Branch;
import com.liip.platform.service.BranchService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @description 部门信息
 * @author 罗林
 * @date 2020-03-25 17:06:18
 */
@Api(tags = { "部门信息操作接口" })
@RestController
@RequestMapping(value = "/SysBranch")
public class BranchController {

    @Resource
    private BranchService branchService;

    /**
    * 新增
    * @author 罗林
    * @date 2020/03/25
    **/
    @ApiOperation(value = "新增部门信息", notes = "新增部门信息")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "部门id", required = false),
                @ApiImplicitParam(name = "name", value = "部门名称", required = true),
                @ApiImplicitParam(name = "code", value = "编号", required = true),
                @ApiImplicitParam(name = "parentId", value = "父id", required = false),
                @ApiImplicitParam(name = "level", value = "层级", required = false),
                @ApiImplicitParam(name = "sort", value = "排序号", required = false),
                @ApiImplicitParam(name = "createdat", value = "创建时间", required = false),
                @ApiImplicitParam(name = "updatedat", value = "更新时间", required = false)
    })
    @RequestMapping("/insert")
    public ReturnT<String> insert(Branch branch){
        return branchService.insert(branch);
    }

    /**
    * 刪除
    * @author 罗林
    * @date 2020/03/25
    **/
    @ApiOperation(value = "刪除部门信息", notes = "刪除部门信息")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "部门id", required = true)
    })
    @RequestMapping("/delete")
    public ReturnT<String> delete(int id){
        return branchService.delete(id);
    }

    /**
    * 更新
    * @author 罗林
    * @date 2020/03/25
    **/
    @ApiOperation(value = "更新部门信息", notes = "更新部门信息")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "部门id", required = true),
                @ApiImplicitParam(name = "name", value = "部门名称", required = false),
                @ApiImplicitParam(name = "code", value = "编号", required = false),
                @ApiImplicitParam(name = "parentId", value = "父id", required = false),
                @ApiImplicitParam(name = "level", value = "层级", required = false),
                @ApiImplicitParam(name = "sort", value = "排序号", required = false),
                @ApiImplicitParam(name = "createdat", value = "创建时间", required = false),
                @ApiImplicitParam(name = "updatedat", value = "更新时间", required = false)
    })
    @RequestMapping("/update")
    public ReturnT<String> update(Branch branch){
        return branchService.update(branch);
    }

    /**
    * 查询 根据主键 id 查询
    * @author 罗林
    * @date 2020/03/25
    **/
    @ApiOperation(value = "根据主键 id 查询部门信息", notes = "根据主键 id 查询部门信息")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "部门id", required = true)
    })
    @RequestMapping("/load")
    public Branch load(int id){
        return branchService.load(id);
    }

    /**
    * 查询 分页查询
    * @author 罗林
    * @date 2020/03/25
    **/
    @ApiOperation(value = "分页查询 部门信息", notes = "分页查询 部门信息")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "offset", value = "页码", required = true ),
                @ApiImplicitParam(name = "pagesize", value = "数量", required = true )
    })
    @RequestMapping("/pageList")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int offset,
                                        @RequestParam(required = false, defaultValue = "10") int pagesize) {
        return branchService.pageList(offset, pagesize);
    }

}
